import { createApp } from 'vue'
import preview from './src/image-preview.vue'
let messageInstance: any = null

const init = (options: any) => {
  messageInstance = createApp(preview, options)
  // vue3不支持未挂载实例，必须得挂载
  const parent = document.createElement('div')
  const instance: any = messageInstance.mount(parent)
  document.body.appendChild(instance?.$el)
  return {
    then(fn: any) {
      instance.callback = (action: any, value: any) => {
        fn({ action, value })
      }
    }
  }
}

export default (options: any) => {
  return init(options)
}

// export default {
//   // 返回 install 函数 用于 Vue.use 注册
//   install(app: any) {
//     app.config.globalProperties.$ImgPrview = caller
//   }
// }
